﻿using System;

namespace KC.Business.Text.Parsers
{
	public class LargeText
	{
		/// <summary>Finds the index of the next line in an array which matches a query</summary>
		/// <param name="Document">string array to search in</param>
		/// <param name="query">String to search for</param>
		/// <returns>Index of result or -1</returns>
		public static int FindLine(string[] Document, string query)
		{
			if (Document == null) throw new ArgumentNullException("Document");
			if (string.IsNullOrEmpty(query)) throw new ArgumentNullException("query");

			for (int i = 0; i < Document.Length; i++)
				if (Document[i].ToLower().Contains(query.ToLower().Trim())) return i;
			return -1;
		}
		/// <summary>Finds the index of the next line in an array which matches a query</summary>
		/// <param name="Document">string array to search in</param>
		/// <param name="query">String to search for</param>
		/// <param name="StartLine">Start looking from this line index</param>
		/// <returns>Index of result or -1</returns>
		public static int FindLine(string[] Document, string query, int StartLine)
		{
			if (Document == null) throw new ArgumentNullException("Document");
			if (string.IsNullOrEmpty(query)) throw new ArgumentNullException("query");

			if (StartLine < 0) StartLine = 0;
			if (StartLine > Document.Length - 1) return -1;
			for (int i = StartLine; i < Document.Length; i++)
				if (Document[i].ToLower().Contains(query.ToLower().Trim())) return i;
			return -1;
		}
	}
}
